import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/index'
import Login from '../views/Login.vue'

import dashboard from './dashboard.js'
import account from './accountmanage.js'

Vue.use(Router);

const router = new Router({
  
  routes: [
        {path: '/', redirect: '/login'},
        { path: '/login', component: Login},
        { path: '/home',
          name: 'Home',
          component: resolve => require(['../components/common/Home.vue'], resolve),
          children: [
             {path: '/emptypage', name: 'emptypage', component: resolve => require(['../views/EmptyPage.vue'], resolve)},
             {path: '/putloglist', name: 'putloglist', component:resolve => require(['../views/loan/finance/PutlogList.vue'], resolve)},
             {path: '/repaymentloglist', name: 'repaymentloglist', component:resolve => require(['../views/loan/finance/RepaymentList.vue'], resolve)},
             {path: '/reportlist', name: 'reportlist', component:resolve => require(['../views/loan/finance/ReportList.vue'], resolve)},
             {path: '/productlist', name: 'productlist', component:resolve => require(['../views/loan/productmanage/ProductList.vue'], resolve)},
             {path: '/amountlist', name: 'amountlist', component:resolve => require(['../views/loan/productmanage/AmountList.vue'], resolve)},
             {path: '/helpcenter', name: 'helpcenter', component:resolve => require(['../views/loan/productmanage/HelpCenter.vue'], resolve)}, 
             {path: '/userlist', name: 'userlist', component:resolve => require(['../views/loan/usermanage/UserList.vue'], resolve)}, 
             {path: '/usersug', name: 'usersug', component:resolve => require(['../views/loan/usermanage/UserSug.vue'], resolve)}, 
             {path: '/userdetail', name: 'userdetail', component:resolve => require(['../views/loan/usermanage/UserDetail.vue'], resolve)}, 
             {path: '/passingrate', name: 'passingrate', component: resolve => require(['../views/loan/statisticsmanage/PassingRate.vue'], resolve) },
             {path: '/overduerate', name: 'overduerate', component: resolve => require(['../views/loan/statisticsmanage/OverdueRate.vue'], resolve) },
             {path: '/rateofreturn', name: 'rateofreturn', component: resolve => require(['../views/loan/statisticsmanage/RateOfReturn.vue'], resolve)},
             {path: '/promotionlist', name: 'promotionlist', component: resolve => require(['../views/loan/operatormanage/PromotionList.vue'], resolve)},
             {path: '/buildinmsg', name: 'buildinmsg', component: resolve => require(['../views/loan/operatormanage/BuildInMsg.vue'], resolve)},
             {path: '/manualmsg', name: 'manualmsg', component: resolve => require(['../views/loan/operatormanage/ManualMsg.vue'], resolve)},
             {path: '/flataccount', name: 'flataccount', component: resolve => require(['../views/loan/reviewmanage/FlatAccountList.vue'], resolve)},
             {path: '/channeldata', name: 'channeldata', component: resolve => require(['../views/loan/operatordata/ChannelData.vue'], resolve)},
             {path: '/blackuserrate', name: 'blackuserrate', component: resolve => require(['../views/loan/operatordata/BlackUserRate.vue'], resolve)},
             {path: '/loanlist', name: 'loanlist', component:resolve => require(['../views/loan/loanmanage/LoanList.vue'], resolve)},
             {path: '/loandetail', name: 'loandetail', component:resolve => require(['../views/loan/loanmanage/LoanDetail.vue'], resolve)},
             {path: '/backmoneylist', name: 'backmoneylist', component:resolve => require(['../views/loan/loanmanage/BackMoneyList.vue'], resolve)},
             {path: '/putmoneylist', name: 'putmoneylist', component:resolve => require(['../views/loan/loanmanage/PutMoneyList.vue'], resolve)},
             {path: '/artificialdata', name: 'artificialdata', component:resolve => require(['../views/loan/riskmanage/ArtificialData.vue'], resolve)},
             {path: '/artificialdetail', name: 'artificialdetail', component:resolve => require(['../views/loan/riskmanage/ArtificialDetail.vue'], resolve)},
             {path: '/artificialreviewlist', name: 'artificialreviewlist', component:resolve => require(['../views/loan/riskmanage/ArtificialReviewList.vue'], resolve)},
             {path: '/artificialreviewsta', name: 'artificialreviewsta', component:resolve => require(['../views/loan/riskmanage/ArtificialReviewStatistic.vue'], resolve)},
             {path: '/artificialtriallist', name: 'artificialtriallist', component:resolve => require(['../views/loan/riskmanage/ArtificialTrialList.vue'], resolve)},
             {path: '/artificialtrialsta', name: 'artificialtrialsta', component:resolve => require(['../views/loan/riskmanage/ArtificialTrialStatistic.vue'], resolve)},
             {path: '/machinedata', name: 'machinedata', component:resolve => require(['../views/loan/riskmanage/MachineData.vue'], resolve)},
             {path: '/myauditfirlist', name: 'myauditfirlist', component:resolve => require(['../views/loan/myaudit/MyAuditFirst.vue'], resolve)}, 
             {path: '/myauditfirdetail', name: 'myauditfirdetail', component:resolve => require(['../views/loan/myaudit/MyAuditFirDetail.vue'], resolve)}, 
             {path: '/myauditseclist', name: 'myauditseclist', component:resolve => require(['../views/loan/myaudit/MyAuditSecond.vue'], resolve)}, 
             {path: '/myauditsecdetail', name: 'myauditsecdetail', component:resolve => require(['../views/loan/myaudit/MyAuditSecDetail.vue'], resolve)},  
             {path: '/remindlist', name: 'remindlist', component:resolve => require(['../views/loan/remind/RemindList.vue'], resolve)},
             {path: '/reminddetail', name: 'reminddetail', component:resolve => require(['../views/loan/remind/RemindDetail.vue'], resolve)},
             {path: '/myremindlist', name: 'myremindlist', component:resolve => require(['../views/loan/remind/MyRemindList.vue'], resolve)},
             {path: '/myreminddetail', name: 'myreminddetail', component:resolve => require(['../views/loan/remind/MyRemindDetail.vue'], resolve)},
             {path: '/remindstatics', name: 'remindstatics', component:resolve => require(['../views/loan/remind/RemindStatics.vue'], resolve)},
             {path: '/serviceconfig', name: 'serviceconfig', component:resolve => require(['../views/loan/productmanage/ServiceConfig.vue'], resolve)},

             {path: '/collectionlist', name: 'collectionlist', component:resolve => require(['../views/loanafter/CollectionList.vue'], resolve)}, 
             {path: '/mycollectionlist', name: 'mycollectionlist', component:resolve => require(['../views/loanafter/MyCollectionList.vue'], resolve)}, 
             {path: '/dayreportlist', name: 'dayreportlist', component:resolve => require(['../views/loanafter/DayReportList.vue'], resolve)},
             {path: '/workanalysis', name: 'workanalysis', component:resolve => require(['../views/loanafter/Workanalysis.vue'], resolve)},
             {path: '/collectiondetail', name: 'collectiondetail', component:resolve => require(['../views/loanafter/CollectionDetail.vue'], resolve)},
             {path: '/remissionloglist', name: 'RemissionLogList', component:resolve => require(['../views/loanafter/RemissionLogList.vue'], resolve)},

             {path: '/ruleEngine', name: 'ruleEngine', component: resolve => require(['../views/loan/systemconfig/RuleEngine.vue'], resolve) },
             {path: '/ruleList', name: 'ruleList', component: resolve => require(['../views/loan/systemconfig/RuleList.vue'], resolve) },
             {path: '/AddRuleEngine', name: 'AddRuleEngine', component: resolve => require(['../views/loan/systemconfig/AddRuleEngine.vue'], resolve) },
             {path: '/setRuleGather', name: 'setRuleGather', component: resolve => require(['../views/loan/systemconfig/SetRuleGather.vue'], resolve) },
             {path: '/ruleDetailList', name: 'ruleDetailList', component: resolve => require(['../views/loan/systemconfig/RuleDetailList.vue'], resolve) },
             {path: '/userrisklist', name: 'userRiskList', component: resolve => require(['../views/loan/systemconfig/UserRiskList.vue'], resolve) },
             {path: '/dictionary', name: 'dictionary', component: resolve => require(['../views/loan/systemconfig/Dictionary.vue'], resolve) },
             {path: '/thirdmanagelist', name: 'ThirdManageList', component: resolve => require(['../views/loan/thirdmanage/ThirdManageList.vue'], resolve) },
             //甲乙共用
             {path: '/userlists', name: 'userlists', component:resolve => require(['../views/loan/usermanage/UserList.vue'], resolve)},
             {path: '/usersugs', name: 'usersugs', component:resolve => require(['../views/loan/usermanage/UserSug.vue'], resolve)},
             {path: '/loanlists', name: 'loanlists', component:resolve => require(['../views/loan/loanmanage/LoanList.vue'], resolve)},
             {path: '/backmoneylists', name: 'backmoneylists', component:resolve => require(['../views/loan/loanmanage/BackMoneyList.vue'], resolve)},
             {path: '/putmoneylists', name: 'putmoneylists', component:resolve => require(['../views/loan/loanmanage/PutMoneyList.vue'], resolve)},
             {path: '/passingrates', name: 'passingrates', component: resolve => require(['../views/loan/statisticsmanage/PassingRate.vue'], resolve) },
             {path: '/rateofreturns', name: 'rateofreturns', component: resolve => require(['../views/loan/statisticsmanage/RateOfReturn.vue'], resolve)},
             //电话销售1.1新功能
             {path: '/telemarketlist', name: 'telemarketlist', component: resolve => require(['../views/loan/telemarket/MarketList.vue'], resolve) },
             {path: '/mymarketing', name: 'mymarketing', component: resolve => require(['../views/loan/telemarket/MyMarketing.vue'], resolve) },
             {path: '/dailyperformance', name: 'dailyperformance', component: resolve => require(['../views/loan/telemarket/DailyPerformance.vue'], resolve) },
             {path: '/dailyconversion', name: 'dailyconversion', component: resolve => require(['../views/loan/telemarket/DailyConversion.vue'], resolve) },

             ...dashboard,
             ...account
          ]
        },
        { path: '*', component: resolve => require(['../components/err/Page404.vue'], resolve)}
  ]
})

//用户是否登陆判断
router.beforeEach((to, from, next) => {
  if (to.path == '/login') {
    sessionStorage.clear()
  }
  let user = sessionStorage.getItem('name')
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    next()
  }
})
router.afterEach(() => {
  window.scrollTo(0, 0)
})

export default router
